package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.admin.TbUser;
import com.dongdongshop.pojo.evaluate.Evaluate;
import com.dongdongshop.service.evaluate.EvaluateService;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@CrossOrigin
@Controller
@RequestMapping("evaluate")
public class EvaluateController {
    private Logger logger = LoggerFactory.getLogger(EvaluateController.class);
    @Reference
    private EvaluateService evaluateService;

    /**
     * 跳转添加页面
     * @param goodsId
     * @param orderId
     * @param model
     * @return
     */
    @RequestMapping("toInsertEvaluate")
    public String toInsertEvaluate(Long goodsId, Long orderId, Model model){
        model.addAttribute("goodsId",goodsId);
        model.addAttribute("orderId",orderId);
        return "evaluation";
    }
    @RequestMapping("insertEvaluate")
    @ResponseBody
    public Result insertEvaluate(Evaluate evaluate){
        TbUser user = (TbUser) SecurityUtils.getSubject().getPrincipal();
        evaluateService.insertEvaluate(evaluate,user.getUsername());
        return Result.ok();
    }
    @RequestMapping("listEvaluate")
    @ResponseBody
    public Result listEvaluate(Long goodsId){
        List<Evaluate> evaluateList = evaluateService.listEvaluate(goodsId);
        return Result.ok().setData(evaluateList);
    }
}
